﻿using System;
using System.Configuration;
using System.Data.Linq;
using System.Web.UI.WebControls;
using BusinessLogic.Model;
using BusinessLogic.Model.Repository;
using BusinessLogic.Model.Repository.NewsItemRepositories;
using BusinessLogic.StateManagers;
using BusinessLogic;

public partial class Main : BasePage
{
    #region PageEvents

    protected void Page_Load(object sender, EventArgs e)
    {
        string title = (string)Application[Constants.Application.WebsiteTitle] ?? "";
        if (!String.IsNullOrEmpty(title))
        {
            Title = title;
        }
    }

    #endregion

    #region ControlEvents

    protected void ldsNewsItems_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        string tagParam = Request.QueryString[QueryStringConstants.Tag];

        INewsItemRepository newsItemRepository = RepositoryFactory.Instance.GetNewsItemRepository();

        e.Result = newsItemRepository.GetByTags(tagParam);
    }

    protected void ldsNewsItems_Deleted(object sender, LinqDataSourceStatusEventArgs e)
    {
        CacheManager.RemoveLatestComments();
        Cache.Remove(Constants.Cache.Tags);

        Response.Redirect(Request.Url.ToString());
    }

    #endregion
}
